<template>
	<view class="content">
		<u-sticky bgColor="#fff">
			<u-tabs :list="list" :is-scroll="false" style="" :current="current" @change="change"></u-tabs>
		</u-sticky>
		<view v-for="(item,index) in jobDetailsArr" :key="index">
			<u-card :title="item.tpName" padding="30" margin="26rpx" :sub-title="item.examinationTime">
				<view class="" slot="body">
					<view>科目：{{ item.title }}</view>
					<view>耗时：{{ item.timeConsuming}}</view>
					<view>得分：{{ item.score}}分</view>
					<view v-if="item.content">评论内容：{{ item.content}}</view>
				</view>
				<view slot="foot" style="display: flex;align-items: center;justify-content: space-between;">
					<view>学员：{{ item.name }}</view>
					<view>
						<button class="mini-btn" type="primary" size="mini" @click="publishJob(item)">评审</button>
						<!-- <button class="mini-btn" type="default" size="mini" v-show="item.isAnnounce==0" @click="editJob(item)">编辑</button> -->
						<!-- <button class="mini-btn" type="warn" size="mini" @click="delJob(item.id)">删除</button> -->
					</view>
				</view>
			</u-card>

		</view>
		<u-modal v-model="show" @confirm="confirm" show-cancel-button :content="content"
			:mask-close-able="true"></u-modal>

		<u-modal v-model="show2" :show-cancel-button="true" confirm-text="提交" title="评审" @cancel="cancel"
			@confirm="confirm2">
			<view class="u-update-content">
				<u-input v-model="content2" type="textarea" border="true" height="150" auto-height="true" />
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		getStuPaperListByStuId,
		edit
	} from '@/api/jz/examination/api.js';
	import {
		getUser
	} from '@/utils/auth';
	export default {
		data() {
			return {
				content: "确认要删除吗？",
				list: [{
					name: '未评审'
				}, {
					name: '已评审',
				}],
				current: 0,
				swiperCurrent: 0,
				isAnnounce: null, //0 保存 ； 1 保存并发布
				jobDetailsArr: [], //作业详情
				show: false,
				show2: false,
				selId: null,
				content2: "",
				valId: null
			}
		},

		mounted() {
			this.change(0)
		},
		methods: {
			async confirm2() {
				let data = {
					id: this.valId,
					content: this.content2
				}
				var res = await edit(data);
				if (res.code == 200) {
					this.change(this.current)
				}

			},
			publishJob(val) {
				this.valId = val.id
				this.show2 = true;
			},
			confirm() {
				let data = {
					id: this.selId,
					delFlag: 1
				}
				editWorkJob(data).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: `删除成功`
						})
						this.change(this.current)
					}
				}).catch((err) => {
					console.error(err);
				});
			},
			getTime(time) {
				// 转换为式分秒
				let h = parseInt(time / 60 / 60 % 24)
				h = h < 10 ? '0' + h : h
				let m = parseInt(time / 60 % 60)
				m = m < 10 ? '0' + m : m
				let s = parseInt(time % 60)
				s = s < 10 ? '0' + s : s
				// 作为返回值返回
				return h + ":" + m + ":" + s
			},

			change(index) {
				this.current = index;
				getStuPaperListByStuId(this.selId).then((res) => {
					if (res.code == 200) {
						this.jobDetailsArr = []
						for (var i = 0; i < res.data.length; i++) {
							res.data[i].timeConsuming = this.getTime(res.data[i].timeConsuming)
							if (index == 0) {
								if (res.data[i].teacherId == null) {
									this.jobDetailsArr.push(res.data[i])
								}
							} else {
								if (res.data[i].teacherId) {
									this.jobDetailsArr.push(res.data[i])
								}
							}
						}

					}
				}).catch((err) => {
					console.error(err);
				});

			},
		},
		onLoad: function(options) {
			this.selId = options.id;
		},
	}
</script>

<style scoped>
	page {
		height: 100%;
		background-color: #f2f2f2;
	}
</style>
<style scoped lang="scss">
	.u-card-wrap {
		background-color: $u-bg-color;
		padding: 1px;
	}

	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}

	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}
</style>